package com.hmdp;

import org.yaml.snakeyaml.util.ArrayUtils;

import java.lang.reflect.Array;
import java.util.*;

public class test {
    public static void main(String[] args) {
        int i = 1,j = 2,k = 3;
        Integer[] arr = {i,j,k};
        Arrays.sort(arr);
        List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3,4,3));
        Set<Integer> set = new HashSet<>(list);
        List<Integer>list1 = new ArrayList<>(set);
        System.out.println(list1);
    }

    public int[] twoSum(int[] nums, int target) {
        int[] arr = new int[2];
        HashMap<Integer, Integer> map = new HashMap<>();
        map.put(nums[0],0);
        for (int i = 1; i < nums.length; i++) {

            if (map.containsKey(target - nums[i])){
                arr[0] = map.get(target - nums[i]);
                arr[1] = i;
            }
            map.put(nums[i],i);
        }

        return arr;
    }

    public List<List<String>> groupAnagrams(String[] strs) {
        HashMap<String,List<String>> map = new HashMap<>();
        for (String s : strs) {
            char[] chars = s.toCharArray();
            Arrays.sort(chars);
            String s1 = String.valueOf(chars);
            List<String> orDefault = map.getOrDefault(s1,new ArrayList<>());
            orDefault.add(s);
            map.put(s1,orDefault);
        }
        List<List<String>> arrayLists = new ArrayList<>();
        for (String s : map.keySet()) {
            arrayLists.add(map.get(s));
        }
        return  arrayLists;
    }


    public int longestConsecutive(int[] nums) {
        HashSet<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int length = 0;
        int currentNum = 0;
        int max = 0;
        for (Integer num : set) {
            //如果是起点
            if (!set.contains(num-1)){
                length = 1;
            }else {
                continue;
            }
            currentNum = num;
            while(set.contains(currentNum+1)){
                    currentNum++;
                    length++;
            }
            max = Math.max(max,length);
        }
        return  max;
    }//nums = [100,4,0,1,3,0]

    public void moveZeroes(int[] nums) {
        int left = 0,right = 0;
        while(right<nums.length){
            if (nums[right]!=0){
                swap(nums,left,right);
                left++;
            }
            right++;
        }
    }

    void swap(int[] num,int i,int j){
        int temp;
        temp = num[i];
        num[i] = num[j];
        num[j] = temp;
        List<List<Integer>>list = new ArrayList<>();
        list.add(new ArrayList<>(Arrays.asList()));
        int[] unique = Arrays.stream(num).distinct().toArray();


    }

       //[-1,0,1,2,-1,-4]
        //[-4,-1,-1,0,1,2]  [0,0,0,0]
    public List<List<Integer>> threeSum(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        
        return null;
    }
}
